<template>
  <div class="order-wrapper">
  	<mt-header fixed title="修改密码">
        <router-link to="/home/my" slot="left">
		    <mt-button icon="back">返回</mt-button>
		</router-link>
        <mt-button slot="right" @click="getpasswordsend">保存</mt-button>
    </mt-header>
    <div class="order-wrapper-context">
        <div class="pas">
          <mt-field label="原密码" placeholder="请输入旧密码" type="password" v-model="oldpassword"></mt-field>
          <mt-field label="新密码" placeholder="请输入新密码" type="password" v-model="newpassword"></mt-field>
          <mt-field label="新密码" placeholder="请再次输入新密码" type="password" v-model="newpassword2"></mt-field>
        </div>
    </div>
  </div>
</template>

<script>
import axios from '@/api/axios';
import { mapGetters, mapMutations} from 'vuex';
import { Toast, MessageBox, Indicator } from 'mint-ui';
export default {
	data: function () {
		return {
            userinfo: this.getId(),
            newpassword: '',
            newpassword2: '',
            oldpassword: ''
        }
    },
    created: function () {
    },
    methods: {
        ...mapGetters(['getId']),
        getpasswordsend: function () {
            if(this.newpassword === this.newpassword2){
                this.getpasswordresult();
            }else{
                MessageBox.alert('两次新密码不符请重新输入！').then(action => { this.newpassword = ''; this.newpassword2 = ''; this.oldpassword = ''});                
            }
        },
        getpasswordresult: function () {
            Indicator.open("请稍后...");
            var data = {
                id: this.userinfo,
                newpassword: this.newpassword,
                oldpassword: this.oldpassword
            };
            var setting = {
                method: 'POST',
                url: '/getUserModifyInformation',
            };
            axios.call(this, (res) => { this.getpasswordresultCallback(res); }, {setting: setting, data:data })
        },
        getpasswordresultCallback: function (res) {
            Indicator.close();
            if(res.code === 0){
                MessageBox.alert('修改成功,点击确认后退出登录！').then(action => { });
            }else{
                MessageBox.alert('修改失败，请重新尝试！');
            }
        }
    }
}
</script>

<style>
  @import '../../assets/css/mypages/my.css';
</style>
